from digits import digits
from math import log10

def fact(n):
    result = 1;
    
    while n > 0:
        result *= n
        n -= 1
        
    return result

factorials = [fact(x) for x in range(0, 10)]

def isCurious(n):
    return n == sum(factorials[d] for d in digits(n))

n = 10

while n < (1 + log10(n)) * factorials[9] :
    if isCurious(n):
        print n
        
    n += 1
    
